﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using School.Entities;
namespace School.Pages.Evaluation
{
    public partial class New_Evaluation : System.Web.UI.Page
    {
        static public SchoolEntities db = new SchoolEntities();
        protected void Page_Load(object sender, EventArgs e)
        {
            
           
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            try
            {
                
                TE_Evaluation eva = new TE_Evaluation()
                {  
                    Name = eva_name.Text,
                    Grade_Id = Int64.Parse(((DropDownList)evaluation_new1.FindControl("ddlGrade")).SelectedValue),
                    
                    
                    Evaluation_Type_Id = int.Parse(((DropDownList)evaluation_new1.FindControl("ddlevaluation_type")).SelectedValue),
                    MinDegree = Convert.ToSingle(mindegree.Text),
                    MaxDegree = Convert.ToSingle(maxdegree.Text),
                    details = (details.Text)
                };
                db.AddToTE_Evaluation(eva);
                db.SaveChanges();
               Int64 [] arr = new Int64[1000];
               
                for (int i = 0; i < ((ListBox)evaluation_new1.FindControl("ddlsubject")).Items.Count;i++ )
               {
                   if (((ListBox)evaluation_new1.FindControl("ddlsubject")).Items[i].Selected)
                   {
                      
                       TE_Evaluation_Subject subject = new TE_Evaluation_Subject() { evaluation_id = eva.Id, subject_id= int.Parse(((ListBox)evaluation_new1.FindControl("ddlsubject")).Items[i].Value) };
                       db.AddToTE_Evaluation_Subject(subject);
                       db.SaveChanges();
                   }
               
                }
                for (int i = 0; i < ((ListBox)evaluation_new1.FindControl("ddlclass")).Items.Count; i++)
                {
                    if (((ListBox)evaluation_new1.FindControl("ddlclass")).Items[i].Selected)
                    {
                        int x = int.Parse(((ListBox)evaluation_new1.FindControl("ddlclass")).Items[i].Value);
                        TE_Evaluation_Class classs = new TE_Evaluation_Class() { evaluation_id = eva.Id, class_id = x};
                        db.AddToTE_Evaluation_Class(classs);
                        db.SaveChanges();
                                            }
                }
                Label1.Text = "نجحت عملية التسجيل";

            }
            catch
            {
                Label1.Text = "برجاء تحديد الماده والفصل و نوع التقيم";
               
                Response.Redirect("New_Evaluation.aspx");
            }




        }







    }
}
